package edu.kjxy.demo0408;

public class Person {
	String idno = "公安局在分配";  //身份证号
	String name = "无名氏";			//属性，也称为成员变量
	String birthday = "看日历";
	String gender = "暂时保密";    //性别
	
	Car car; //人可以拥有一辆车
	
	static int count = 0;	//静态变量， 隶属于类， 在类上操作，对象也可以操作
	
	public static final int LEGS = 2;
	
	//没有自定义的， 会默认生成无参的构造函数
	public Person() {
		count++;
	}

	public Person(String idno, String birthday, String gender) {
		this.idno = idno;
		this.birthday = birthday;
		this.gender = gender;
		count++;
	}

	//构造函数与类名相同， 无返回类型声明， 返回新建的对象， 
	//可以重载， 本质是静态函数， 用来初始化对象属性
	public Person(String idno, String name, String birthday, String gender)
	{
		this.idno = idno;
		this.name = name;
		this.birthday = birthday;
		this.gender = gender;
		count++;
	}
	
	public Person(String idno, String name, String birthday, String gender, Car car) {
		super();
		this.idno = idno;
		this.name = name;
		this.birthday = birthday;
		this.gender = gender;
		this.car = car;
		count++;
	}

	@Override
	public String toString() {
		return "Person [idno=" + idno + ", name=" + name + ", birthday=" + birthday + ", gender=" + gender + "]";
	}

	public void eat(String food) {
		System.out.println(name + "中午吃" + food);
		System.out.println(count); 	//间接指向对象的类的静态变量
	}
	
	public void sleep(int hour) {
		System.out.println(name + "晚上睡" + hour + "个小时");
	}
	
	//在人类对象中调用车对象的方法
	public void travel(String place) {
		System.out.println(name + "去" + place);
		if(car != null)
			car.dirve(place);
		else
			System.out.println(name + "走路去" + place);
	}
	
	public static int GetCount() {
		System.out.println("几个人：" + count);
		return count;
	}
}
